<template>
    <div>
        <div class="e-form">
        <BillTop @cancel="handleClose"></BillTop>
            <div class="tabs" style="margin-bottom: 120px">
                <div class="tabs-title">基本信息</div>
                <div style="width: 100%" class="form">
                    <el-form
                        :model="formData"
                        :label-width="formLabelWidth"
                        ref="ruleForm"
                        class="demo-ruleForm"
                    >
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="机构：">
                                    <span>{{ formData.orgName }}</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="录入人员：">
                                    <span>{{ formData.founderName }}</span>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="状态：">
                                    <span>草稿</span>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item
                                    label="结算日期："
                                    prop="settlementDate"
                                >
                                    <el-date-picker
                                        v-model="formData.settlementDate"
                                        type="date"
                                        placeholder="选择日期"
                                        value-format="yyyy-MM-dd"
                                        :clearable="false"
                                    >
                                    </el-date-picker>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="备注：">
                                    <el-input
                                        type="textarea"
                                        v-model="formData.remarks"
                                        :rows="2"
                                        resize="none"
                                        autocomplete="off"
                                        maxlength='500'
                                    ></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </div>
            </div>
            <div class="buttons">
                <el-button
                    type="primary"
                    size="small"
                    style="background: #2e61d7"
                    @click="addSave"
                    >保存</el-button
                >
                <el-button size="small" @click="handleClose">取消</el-button>
            </div>
        </div>
    </div>
</template>

<script>
import { mapState } from 'vuex'
import auditRequest from '@/api/materialSettlement/materialProcurement.js'
import { hideLoading } from '@/utils/common'
export default {
    data () {
        return {
            //基础信息
            formData: {
                billNo: '', //	结算编号
                orgName: '', //机构name
                orgId: '', //机构id 不显示
                businessType: 0, //业务类型
                sourceBillNo: '', //源单编号
                sourceBillId: '', //元旦id 不显示
                settlementUnitName: '', //结算单位
                settlementUnitId: '', //结算单位id 不显示
                settlementDate: '', //结算日期
                amount: 0, //结算金额 元
                acceptancePersonnelName: '', //经办人员名称
                acceptancePersonnelId: '', //经办人人员id
                invoiceNo: '', //发票编号
                freight: 0, //运输服务费
                taxRate: 0, //税率
                totalAmount: 0, //税价合计
                taxAmount: 0, //税额
                taxDifference: 0, //税额差额
                billSource: 2, //单据来源(1:新增;2:验结一体)
                billSourcetxt: '验结一体',
                isOffsetAdvancePayment: false, //是否冲预付款 需要转数字
                offsetAdvancePayment: null, // 	冲预付款金额(元)
                isPersonalBorrowing: false, //是否冲个人借资 需要转数字
                acceptanceBillNo: '', //验收编号
                personalBorrowing: 0, //	冲个人借资(元)
                // 1isPersonalBorrowing2personalBorrowing3reversalObjectNumber,reversalObjectId
                //4 borrowerName , borrowerId
                reversalObjectNumber: '', //	冲销对象编号
                reversalObjectId: '', //	冲销对象id 不显示
                currency: '', //币种名称
                currencyId: '', //币种id 不显示
                borrowerName: '', //借资人员名称
                borrowerId: '', //借资人员id 不显示
                baseCurName: '', //本位币名称
                baseCurId: '', //本位币id 不显示
                baseCurRate: 0, //本位币汇率 不显示
                baseCurAmount: 0, //结算金额(本位币)
                remarksL: '', //备注
                state: 0, //单据状态
                founderName: '', //创建人
                founderId: '', //创建人id 不显示
                acceptanceBillId: '',
                baseCurTaxAmount: 0,
                baseCurTotalAmount: 0,
                billId: '',
                easId: '',
                evaluationLevel: null,
                gmtCreate: '',
                gmtModified: '',
                isEndSettle: 0,
                isRed: 0,
                nullifyCreated: '',
                nullifyCreator: '',
                nullifyCreatorId: '',
                nullifyDescription: '',
                nullifyReason: '',
                purchasingUnitId: '',
                purchasingUnitName: '',
                redBillState: 0,
                remarks: '',
                rmbAmount: 0,
                rmbId: '',
                rmbName: '',
                rmbRate: 0,
                rmbTaxAmount: 0,
                rmbTotalAmount: 0,
                sourceBillName: '',
                sourceId: '',
                sourceNumber: '',
                workId: '',
                unoffsetAdvancePayment: null,
            },
            formLabelWidth: '200px',
            billid: ''
        }
    },
    async mounted () {
        if (this.$route.query.isRedSingle === '1') {
            this.formData = await auditRequest.chonghongdan({
                id: this.$route.query.billid,
                billId: this.$route.query.billid
            })
        } else {
            const { baseCyByOrgId } = this.userInfo
            console.log(baseCyByOrgId, 'rr')
            this.user = JSON.parse(localStorage.getItem('vuex'))
            this.$set(
                this.formData,
                'founderName',
                this.user.userInfo.userName
            )
            this.$set(this.formData, 'founderId', this.user.userInfo.userId)
            this.$set(
                this.formData,
                'orgName',
                this.user.userInfo.orgInfo.orgName
            )
            this.$set(this.formData, 'orgId', this.user.userInfo.orgInfo.orgId)
            this.$set(
                this.formData,
                'acceptancePersonnelName',
                this.user.userInfo.userName
            )
            this.$set(this.formData, 'billSource', 1)
            this.$set(this.formData, 'billSourcetxt', '新增')
        }

        // const { baseCyByOrgId } = this.userInfo
        // console.log(baseCyByOrgId, 'rr')
        // this.user = JSON.parse(localStorage.getItem('vuex'))
        // this.$set(this.formData, 'founderName', this.user.userInfo.userName)
        // this.$set(this.formData, 'founderId', this.user.userInfo.userId)
        // this.$set(this.formData, 'orgName', this.user.userInfo.orgInfo.orgName)
        // this.$set(this.formData, 'orgId', this.user.userInfo.orgInfo.orgId)
        // this.$set(this.formData, 'acceptancePersonnelName', this.user.userInfo.userName)
        // this.$set(this.formData, 'billSource', 1)
        // this.$set(this.formData, 'billSourcetxt', '新增')

        // this.formData.founderName = this.userInfo.userName  //录入人员
        // this.formData.founderId = this.userInfo.userId

        // this.formData.orgName = this.userInfo.orgInfo.orgName
        // this.formData.orgId = this.userInfo.orgInfo.orgId

        // this.formData.baseCurName = baseCyByOrgId.currencyName  //本位币
        // this.formData.baseCurId = baseCyByOrgId.currency
    },
    components: {},
    computed: {
        ...mapState({
            userInfo: state => state.userInfo,
            currencyForm: state => state.equip.equipData.currencyForm, //币种
            state: state => state.equip.equipData.state //通用流程状态
        })
    },
    created () {
        this.getNowTime()
    },
    methods: {
        getNowTime () {
            var now = new Date()
            var year = now.getFullYear() //得到年份
            var month = now.getMonth() //得到月份
            var date = now.getDate() //得到日期
            month = month + 1
            month = month.toString().padStart(2, '0')
            date = date.toString().padStart(2, '0')
            var defaultDate = `${year}-${month}-${date}`

            this.$set(this.formData, 'settlementDate', defaultDate)
            // alert(this.formData.settlementDate)
        },
        //新增基本信息
        addSave () {
            // showLoading()

            this.formData.isOffsetAdvancePayment == true
                ? (this.formData.isOffsetAdvancePayment = 1)
                : (this.formData.isOffsetAdvancePayment = 0)

            this.formData.isPersonalBorrowing == true
                ? (this.formData.isPersonalBorrowing = 1)
                : (this.formData.isPersonalBorrowing = 0)
            // auditRequest.savejibenxinxi(this.formData)
            auditRequest.savejibenxinxi(this.formData).then(res => {
                this.clientPop(
                    'info',
                    '保存成功!是否进行下一步操作？',
                    () => {
                        this.$router.push({
                            path: '/materialProcurementEdit',
                            query: {
                                billid: res,
                                name: 'planDetail'
                            }
                        })
                    },
                    null,
                    this.handleClose
                )
            })
        },
        //取消
        handleClose () {
            hideLoading()
            this.$router.replace('/materialProcurementList')
        }
    }
}
</script>

<style lang="scss" scoped>
.buttons {
    left: 0;
}
.e-form {
    padding: 0 20px;
    .tabs-title::before {
        content: '';
        height: 22px;
        width: 8px;
        border-radius: 40px;
        background-color: #2e61d7;
        display: block;
        position: absolute;
        left: 20px;
        margin-right: 20px;
    }
}
.e-table {
    min-height: auto;
    background: #fff;
}
.separ {
    width: 30px;
    height: 40px;
    line-height: 18px;
    text-align: center;
}
.upload {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    text-align: center;
}

.upload-demo {
    display: flex;
    justify-content: center;
    align-items: center;
}

::v-deep.el-input--suffix .el-input__inner {
    padding-right: 5px;
}
::v-deep.el-table .cell {
    text-align: center;
}
</style>
